import subprocess
import time
import xml.etree.ElementTree as ET

def run_adb_command(command):
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output, error

def check_for_data(xml_content):
    tree = ET.ElementTree(ET.fromstring(xml_content))
    root = tree.getroot()
    for elem in root.iter():
        if elem.attrib.get('content-desc') == "暂无数据":
            return False
    return True

def main_loop():
    while True:
        # 获取屏幕布局
        run_adb_command("adb shell uiautomator dump")
        output, _ = run_adb_command("adb pull /sdcard/window_dump.xml")

        # 检查布局文件
        with open("window_dump.xml", "r") as file:
            xml_content = file.read()

        if check_for_data(xml_content):
            # 当页面不是“暂无数据”时，执行所需操作
            print("页面上没有找到 '暂无数据'，执行操作")
            # 这里可以添加需要的操作

        # 等待一段时间后再次检查
        time.sleep(10)

main_loop()
